/*
 *@(#)RssFeedFactory.java 1.0 Mar 27, 2008
 *refered http://hi.baidu.com/openj/blog/item/eb47dd01c713b8021d95839b.html
 *
 */
package codebush.service.support;

import java.util.ArrayList;
import java.util.List;

import com.sun.syndication.feed.rss.Channel;
import com.sun.syndication.feed.rss.Description;
import com.sun.syndication.feed.rss.Item;
import com.sun.syndication.io.FeedException;
import com.sun.syndication.io.WireFeedOutput;

/**
 * 
 * @author Fution Bai
 * @since 1.0
 */
public class RssFeedFactory {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 新建Channel对象，对应rss中的<channel></channel>
		Channel channel = new Channel("rss_2.0");
		channel.setTitle("Test RSS channel's title");
		channel.setDescription("channel的描述");
		channel.setLink("http://hi.baidu.com/openj/rss");
		channel.setEncoding("UTF-8");

		// 这个list对应rss中的item列表
		List<Item> items = new ArrayList<Item>();
		// 新建Item对象，对应rss中的<item></item>
		
		Item item = new Item();
		item.setAuthor("item author jnduan");
		item.setTitle("item title");
		// 新建一个Description，它是Item的描述部分
		Description description = new Description();
		description.setType("item description type");
		description.setValue("item description value");
		item.setDescription(description);

		items.add(item);
		channel.setItems(items);

		// 用WireFeedOutput对象输出rss文本
		WireFeedOutput out = new WireFeedOutput();
		try {
			System.out.println(out.outputString(channel));
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (FeedException e) {
			e.printStackTrace();
		}
	}
}
